//定义模块
define(['jquery','login','register'],function($){
    function Header(){
        this.load();
       
    };
    $.extend(Header.prototype,{
        load:function(){
            $('header').load('../html/header-modal.html nav',$.proxy(this.addListener,this));
           

           
           
            
          
         
        },
        addListener(){
            this.isLogin();
            //弹模态框
            $("#btnLogin").click(function(){
               
                $("#loginModal").modal({
                    backdrop:'static'
                })
            });
            $("#btnReg").click(function(){
               
                $("#regModal").modal({
                    backdrop:'static'
                })
            });
            //退出按钮
            $('.link-logout').on('click',this.logoutHandler);
            //active
            $(".max-title").on('click','a',(event)=>{
            $(event.target).parent('li').addClass('active').siblings('li').removeClass('active')
            })
        },
        isLogin(){
            const username = sessionStorage.loginUser;
            if(username){//登录成功
              
                $('.already-login').removeClass('hidden')
                                    .find('.link-username').text(username).end()
                                    .siblings('.not-login').remove();
            }
        },
        //退出
        logoutHandler(){
          
            const url ='http://rap2api.taobao.org/app/mock/119523/api/users/logout';
            $.get(url,(data)=>{
                sessionStorage.removeItem('loginUser');
                location.reload();
            })
        }
    });
    return new Header();
})